package cn.hrlly.tao2shou.biz;

import com.zhy.http.okhttp.OkHttpUtils;

import cn.hrlly.tao2shou.other.Config;
import cn.hrlly.tao2shou.R;
import cn.hrlly.tao2shou.callback.ApplicationCallback;
import cn.hrlly.tao2shou.domain.Applications;
import cn.hrlly.tao2shou.domain.Status;
import cn.hrlly.tao2shou.listener.OnConfimApplicationListener;
import okhttp3.Request;

/**
 * User: gengliang
 * Date: 2016-01-30
 * Time: 19:50
 */

public class ConfirmApplicationBizImpl implements ConfirmApplicationBiz {

    private OnConfimApplicationListener onConfimApplicationListener;

    public ConfirmApplicationBizImpl(OnConfimApplicationListener onConfimApplicationListener){
        this.onConfimApplicationListener=onConfimApplicationListener;
    }

    @Override
    public void confirmApplication(Applications applications) {
        OkHttpUtils
                .post()
                .url(Config.key_url)
                .addParams(Config.key_action,Config.action_confirm_application)
                .addParams(Config.key_application_id,applications.getApplicationId())
                .build()
                .execute(new ApplicationCallback() {
                    @Override
                    public void onError(Request request, Exception e) {
                        onConfimApplicationListener.confirmApplicationFail(R.string.network_connection_error);
                    }

                    @Override
                    public void onResponse(Status status) {
                        if(status.getStatus()==0)
                            onConfimApplicationListener.confirmApplicationSucc(R.string.confirm_application_success);
                        else
                            onConfimApplicationListener.confirmApplicationFail(status.getErrorMessage());
                    }
                });
    }
}
